//
//  ZBreathAwareness.swift
//  HIextractLicve
//
//  Created by HIextractLicve on 2024/12/4.
//

import UIKit
import ProgressHUD
import MJRefresh

class ZBreathAwareness: HTLCBasecompression {
    let headerImgHTLC = UIImageView.init()
    let kopJingHTLImgf = UIImageView.init()
    lazy var usernamhrHTl: UILabel = {
        let fancelbk = UILabel.init()
        fancelbk.textColor = .white
        fancelbk.textAlignment = .center
        fancelbk.font = UIFont(name: "Trebuchet MS Bold", size: 17)
        return fancelbk
    }()
    
    var mindfulness:Set<Int>?
    var suggestion:Set<String>?
    var  professionals:Set<CGFloat>?
    var exchangeHTLC:[String:Array<Dictionary<String,String>>]?

    var maingkingNOwRoomDAtaHTLC:Array<Dictionary<String,String>>{
       

       
        if HTLCAllDealRelaxing.Relaxing.signinUserDataHTL["natureImmersion"] != "9834567" {
            return []
        }
       
        return [HTLCAllDealRelaxing.Relaxing.signinUserDataHTL]
    }
    

    lazy var edityouButtonHTLC: THLCNOrBUTTOn = {
        let burrton = THLCNOrBUTTOn.init()
        burrton.setBackgroundImage(UIImage.init(named: "editghHTLC"), for: .normal)
        
            burrton.addTarget(self, action: #selector(passsonToorhtPickHTL(buHTLonf:)), for: .touchUpInside)
      
        
        return burrton
    }()
    
    lazy var wallentButtonHTLC: THLCNOrBUTTOn = {
        let burrton = THLCNOrBUTTOn.init()
        burrton.setBackgroundImage(UIImage.init(named: "mywasll_HTLC"), for: .normal)
       
      
            burrton.addTarget(self, action: #selector(passsonToorhtPickHTL(buHTLonf:)), for: .touchUpInside)
        
       
        return burrton
    }()
    
    
    lazy var fansCountLBLHTLC: UILabel = {
        let fancelbk = UILabel.init()
        fancelbk.textColor = .white
        fancelbk.textAlignment = .center
        fancelbk.font = UIFont(name: "Trebuchet MS Bold", size: 17)
        fancelbk.isUserInteractionEnabled = true
        fancelbk.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(touch_HTLUselistview(tuio:))))
        return fancelbk
    }()
    
    lazy var fancedesclbkLHTLC: UILabel = {
        let fancedesclbk = UILabel.init()
        fancedesclbk.textColor = UIColor(white: 1, alpha: 0.5)
        fancedesclbk.textAlignment = .center
        fancedesclbk.font = UIFont(name: "Trebuchet MS Bold", size: 13)
        fancedesclbk.text = "Fans"
        fancedesclbk.isUserInteractionEnabled = true
        fancedesclbk.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(touch_HTLUselistview(tuio:))))
        return fancedesclbk
    }()
    
    
    
    lazy var follonwerCountLBLHTLC: UILabel = {
        let fancelbk = UILabel.init()
        fancelbk.textColor = .white
        fancelbk.textAlignment = .center
        fancelbk.font = UIFont(name: "Trebuchet MS Bold", size: 17)
        fancelbk.isUserInteractionEnabled = true
        fancelbk.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(touch_HTLUselistview(tuio:))))
        return fancelbk
    }()
    
    lazy var folldedesclbk: UILabel = {
        let fancedesclbk = UILabel.init()
        fancedesclbk.textColor = UIColor(white: 1, alpha: 0.5)
        fancedesclbk.textAlignment = .center
        fancedesclbk.font = UIFont(name: "Trebuchet MS Bold", size: 13)
        
            fancedesclbk.text = "Follow"
        
       
        fancedesclbk.isUserInteractionEnabled = true
        fancedesclbk.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(touch_HTLUselistview(tuio:))))
        return fancedesclbk
    }()
 
    
    
    @objc func touch_HTLUselistview(tuio:UITapGestureRecognizer)  {
        var huihuo = 43
        huihuo += 1
        var pagenorHTLC = 23
        pagenorHTLC -= 2
        let community:Set<Int> = [huihuo,pagenorHTLC]
        if tuio.view == self.fancedesclbkLHTLC || tuio.view == self.fansCountLBLHTLC {
            self.navigationController?.pushViewController(CognitiveReset.init(stressdescHTL: community, HtlPoiu: 0), animated: true)
        }
        
        if tuio.view == self.follonwerCountLBLHTLC || tuio.view == self.folldedesclbk {
            self.navigationController?.pushViewController(CognitiveReset.init(stressdescHTL: community, HtlPoiu: 1), animated: true)
        }
    }
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        usernamhrHTl.text =  HTLCAllDealRelaxing.Relaxing.signinUserDataHTL["HTLCkiName"]
        headerImgHTLC.image = HTLCAllDealRelaxing.Relaxing.showingHTLimgHead
        kopJingHTLImgf.image = HTLCAllDealRelaxing.Relaxing.showingHTLimgHead
        fansCountLBLHTLC.text = "\(HTLCAllDealRelaxing.Relaxing.fancliistHTL.0.count)"
        mindfulness = [99]
        suggestion = ["decompression"]
        professionals = [12.1]
        exchangeHTLC = ["themtopicHTLC":[["decompression":"098"]]]
        follonwerCountLBLHTLC.text = "\(HTLCAllDealRelaxing.Relaxing.focussuuserHTL.0.count)"
    }
    
    lazy var builCollectionLiveViewHTL: UICollectionView = {
        let coijfLayout = UICollectionViewFlowLayout.init()
        coijfLayout.itemSize = CGSize.init(width: (UIScreen.main.bounds.width - 24.xHTL), height:320)
        
        coijfLayout.minimumInteritemSpacing = 12
        coijfLayout.scrollDirection = .vertical
        coijfLayout.minimumLineSpacing = 24
        
        
        let fiettCol = UICollectionView.init(frame: .zero, collectionViewLayout: coijfLayout)
        let nib = UINib(nibName: "MindfulnessPracticeLL", bundle: nil)
               
        fiettCol.register(nib, forCellWithReuseIdentifier: "HTLRDymmmlostViewCellID")
       
        fiettCol.delegate = self
        fiettCol.dataSource = self
       
            fiettCol.showsVerticalScrollIndicator = false
            fiettCol.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: 310, right: 0)
      
        
       fiettCol.showsVerticalScrollIndicator = false
       
        fiettCol.backgroundColor = .clear
        fiettCol.dataSource = self
        fiettCol.mj_header = MJRefreshNormalHeader(refreshingBlock: {
            
            DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
                fiettCol.reloadData()
                fiettCol.mj_header?.endRefreshing()
            }
            
        })
        return fiettCol
    }()
    override func viewDidLoad() {
        super.viewDidLoad()

       
        
        kopJingHTLImgf.contentMode = .scaleToFill
        view.addSubview(kopJingHTLImgf)
        kopJingHTLImgf.snp.makeConstraints { make in
            make.top.leading.trailing.equalToSuperview()
            make.height.equalTo(410)
        }
        let bgLayer1 = CAGradientLayer()
        bgLayer1.colors = [UIColor(red: 0.06, green: 0.07, blue: 0.07, alpha: 0).cgColor, UIColor(red: 0.06, green: 0.07, blue: 0.07, alpha: 1).cgColor]
        bgLayer1.locations = [0, 1]
        bgLayer1.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 410)
        bgLayer1.startPoint = CGPoint(x: 0.5, y: 0)
        bgLayer1.endPoint = CGPoint(x: 1, y: 1)
        kopJingHTLImgf.layer.addSublayer(bgLayer1)
        
        let nortyiButton = UIButton.init()
        nortyiButton.setImage(UIImage.init(named: "icon_siterrHTLC"), for: .normal)
        nortyiButton.addTarget(self, action: #selector(gogonextTonmesglistHTL(hijkBUtton:)), for: .touchUpInside)
        view.addSubview(nortyiButton)
        nortyiButton.snp.makeConstraints { make in
            make.top.equalToSuperview().offset(saaffeeTppoHightHTL + 8)
            make.trailing.equalToSuperview().inset(12.xHTL)
            make.width.equalTo(38.xHTL)
            make.height.equalTo(38.xHTL)
        }
        
        
        headerImgHTLC.contentMode = .scaleToFill
        headerImgHTLC.layer.masksToBounds = true
        headerImgHTLC.layer.cornerRadius = 52
        headerImgHTLC.layer.borderColor = UIColor(red: 1, green: 1, blue: 1, alpha: 0.43).cgColor
        headerImgHTLC.layer.borderWidth = 2.1
        
        
        view.addSubview(headerImgHTLC)
        headerImgHTLC.snp.makeConstraints { make in
            make.top.equalTo(nortyiButton.snp.bottom).offset(70.yHTL)
            make.width.height.equalTo(104.xHTL)
            make.centerX.equalToSuperview()
        }
        let mainScrio = UIScrollView.init()
        
        view.addSubview(mainScrio)
        mainScrio.snp.makeConstraints { make in
            make.leading.bottom.trailing.equalToSuperview()
            make.top.equalTo(headerImgHTLC.snp.bottom)
        }
        
        mainScrio.addSubview(usernamhrHTl)
        usernamhrHTl.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalToSuperview().offset(12)

        }
        
       
        
      
        
        let comye = (UIScreen.main.bounds.width)/2
        
    
        mainScrio.addSubview(fansCountLBLHTLC)
        mainScrio.addSubview(fancedesclbkLHTLC)
      
        mainScrio.addSubview(follonwerCountLBLHTLC)
        mainScrio.addSubview(folldedesclbk)
        
        
        mainScrio.addSubview(edityouButtonHTLC)
        mainScrio.addSubview(wallentButtonHTLC)
        
         
        
        fansCountLBLHTLC.snp.makeConstraints { make in
            make.leading.equalToSuperview()
            make.width.equalTo(comye)
            make.top.equalTo(usernamhrHTl.snp.bottom).offset(31)
            make.height.equalTo(22)
            make.trailing.equalTo(mainScrio.snp.centerX)
        }
        
        fancedesclbkLHTLC.snp.makeConstraints { make in
            make.leading.equalToSuperview()
            make.width.equalTo(comye)
            make.top.equalTo(fansCountLBLHTLC.snp.bottom).offset(5)
            make.height.equalTo(22)
            make.trailing.equalTo(mainScrio.snp.centerX)
        }
        
        
        follonwerCountLBLHTLC.snp.makeConstraints { make in
            make.trailing.equalToSuperview()
            make.width.equalTo(comye)
            make.top.equalTo(usernamhrHTl.snp.bottom).offset(31)
            make.height.equalTo(22)
            make.leading.equalTo(mainScrio.snp.centerX)
        }
        
        folldedesclbk.snp.makeConstraints { make in
            make.trailing.equalToSuperview()
            make.width.equalTo(comye)
            make.top.equalTo(follonwerCountLBLHTLC.snp.bottom).offset(5)
            make.height.equalTo(22)
            make.leading.equalTo(mainScrio.snp.centerX)
        }
        
        edityouButtonHTLC.snp.makeConstraints { make in
            make.leading.equalToSuperview().offset(12.xHTL)
            make.width.equalTo(80.xHTL)
            make.height.equalTo(70.xHTL)
            make.top.equalTo(fancedesclbkLHTLC.snp.bottom).offset(28.xHTL)
        }
        
        wallentButtonHTLC.snp.makeConstraints { make in
            make.trailing.equalToSuperview().inset(12.xHTL)
            make.width.equalTo(258.xHTL)
            make.height.equalTo(70.xHTL)
            make.top.equalTo(fancedesclbkLHTLC.snp.bottom).offset(28.xHTL)
        }
        
        let posdterlbccc = UILabel.init()
        posdterlbccc.textColor = .white
        posdterlbccc.textAlignment = .left
        posdterlbccc.font = UIFont(name: "Trebuchet MS Bold", size: 20)
        posdterlbccc.text = "Post"
        
        
        
        
        
        
        mainScrio.addSubview(posdterlbccc)
        posdterlbccc.snp.makeConstraints { make in
            make.leading.equalToSuperview().offset(12.xHTL)
            make.top.equalTo(wallentButtonHTLC.snp.bottom).offset(36)
        }
       
        
        ProgressHUD.animate()
        DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
            
           
                ProgressHUD.dismiss()
            
            mainScrio.addSubview(self.builCollectionLiveViewHTL)
            self.builCollectionLiveViewHTL.snp.makeConstraints { make in
                make.leading.trailing.equalToSuperview().inset(12)
                make.width.equalTo(UIScreen.main.bounds.width - 24)
                make.bottom.equalToSuperview().offset(-93 - 40)
                make.top.equalTo(posdterlbccc.snp.bottom).offset(16.xHTL)
                make.height.equalTo(320)
            }
           
        }
        
       
        
    }
    @objc func passsonToorhtPickHTL(buHTLonf:UIButton) {
        mindfulness = [99]
        suggestion = ["decompression"]
        professionals = [12.1]
        exchangeHTLC = ["themtopicHTLC":[["decompression":"098"]]]
        if buHTLonf == self.wallentButtonHTLC {
            self.navigationController?.pushViewController(MindBodyConnection.init(), animated: true)
        }
        
        
        if buHTLonf == self.edityouButtonHTLC {
            self.navigationController?.pushViewController(VisualizationExercise.init(), animated: true)
        }

    }

    @objc func gogonextTonmesglistHTL(hijkBUtton:UIButton)  {
        mindfulness = [99]
        suggestion = ["decompression"]
        professionals = [12.1]
        exchangeHTLC = ["themtopicHTLC":[["decompression":"098"]]]
        self.navigationController?.pushViewController(CompassionFocus.init(), animated: true)
    }
    
    
    @objc func editSomentoneHTLC()  {
        mindfulness = [99]
        suggestion = ["decompression"]
        professionals = [12.1]
        exchangeHTLC = ["themtopicHTLC":[["decompression":"098"]]]
        self.navigationController?.pushViewController(VisualizationExercise.init(), animated: true)
        
    }
    
    
    @objc func wallentSomentoneHTLC()  {
        mindfulness = [99]
        suggestion = ["decompression"]
        professionals = [12.1]
        exchangeHTLC = ["themtopicHTLC":[["decompression":"098"]]]
        self.navigationController?.pushViewController(MindBodyConnection.init(), animated: true)
        
    }
    
    
   
}


extension ZBreathAwareness:UICollectionViewDelegate,UICollectionViewDataSource{
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return maingkingNOwRoomDAtaHTLC.count
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let passonHtlacData = maingkingNOwRoomDAtaHTLC[indexPath.row]
        
        let fffuarcell = collectionView.dequeueReusableCell(withReuseIdentifier: "HTLRDymmmlostViewCellID", for: indexPath) as! MindfulnessPracticeLL
        let Timrhg = (passonHtlacData["HTLLiveDYMPiclist"]  ?? "").components(separatedBy: "*")
        fffuarcell.attitudeImageHTl.isHidden = true
        fffuarcell.moreiconHTLc.isHidden = true
        
       
            fffuarcell.oneCupCoverHTLC.image = UIImage(named: Timrhg.first  ?? "")
            fffuarcell.userHeaderHTL.image = UIImage(named: passonHtlacData["HTLCAvater"]  ?? "")
        
       
        fffuarcell.usernamhrHTl.text = "Me"
        fffuarcell.pubtimewHTl.text = passonHtlacData["HTLDYMPunoTime"]
        
        fffuarcell.dyyumTitlewHTl.text = passonHtlacData["HTLLiveDYMDesc"]
        fffuarcell.backgroundColor = .clear
        return fffuarcell
        
        
    }
    
    
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        let passonHtlacData = maingkingNOwRoomDAtaHTLC[indexPath.row]
      
        let enterlive = DeepBreathing.init(stressdescHTL: [233,233,2333], passonHtlacData: passonHtlacData)
        self.navigationController?.pushViewController(enterlive, animated: true)
    }
    
    
}
